package servlet.servlet_yaobo;

import pojo.RelationView;
import pojo.ShoppingCart;
import service.impl.ImpShoppingMemberService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 获取购物车关联表的主要信息
 */
@WebServlet(value = "/shoppingCart")
public class RelationServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ImpShoppingMemberService imp=new ImpShoppingMemberService();
        List<RelationView> rel=new ArrayList<>();
        String cartId=req.getParameter("cartId");
        if(cartId==null) {
            String uid = req.getParameter("u_id");
            ShoppingCart sh = new ShoppingCart();
            sh = imp.sees(Integer.parseInt(uid));
            rel = imp.shooup(sh.getCartId());
        }else {
            rel = imp.shooup(Integer.parseInt(cartId));
        }
        req.setAttribute("rel",rel);
        req.getRequestDispatcher("shoppingCart.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doGet(req, resp);
    }
}
